package test_3_19;

import java.util.PriorityQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 张杰
 * Date: 2022-03-20
 * Time: 16:31
 */

@FunctionalInterface //修饰函数式接口
//函数式接口
interface NoParameterNoReturn {
    //抽象的方法只能有一个
    void test();
}
//无返回值一个参数
@FunctionalInterface
interface OneParameterNoReturn {
    void test(int a);
}
//无返回值多个参数
@FunctionalInterface
interface MoreParameterNoReturn {
    void test(int a,int b);
}
//有返回值无参数
@FunctionalInterface
interface NoParameterReturn {
    int test();
}
//有返回值一个参数
@FunctionalInterface
interface OneParameterReturn {
    int test(int a);
}
//有返回值多参数
@FunctionalInterface
interface MoreParameterReturn {
    int test(int a,int b);
}

public class TestDemo2 {

    public static void main(String[] args) {
        PriorityQueue<Integer> minHeap = new PriorityQueue<>(3,(o1,o2)->o1-o2);
    }

    public static void main4(String[] args) {
        NoParameterReturn noParameterReturn = ()->{return 10;};
        int ret = noParameterReturn.test();
        System.out.println(ret);

        OneParameterReturn oneParameterReturn = (a)->a+11;
        int ret1 = oneParameterReturn.test(10);
        System.out.println(ret1);

        MoreParameterReturn moreParameterReturn = (a,b)->a+b;
        System.out.println(moreParameterReturn.test(2,3));
    }

    public static void main3(String[] args) {
        //无返回值，一个参数
        OneParameterNoReturn oneParameterNoReturn = (a)->{System.out.println(a);};
        oneParameterNoReturn.test(10);

        //无返回值，多个参数
        MoreParameterNoReturn moreParameterNoReturn = (int a,int b)->{System.out.println(a+b);};
        moreParameterNoReturn.test(10,20);
    }

    public static void main2(String[] args) {
        //Lambda表达式 匿名参数法
        NoParameterNoReturn parameterNoReturn = ()-> System.out.println("重写方法！");
        parameterNoReturn.test();
    }
    public static void main1(String[] args) {
        new NoParameterNoReturn() {
            @Override
            public void test() {
                System.out.println("重写的方法！");
            }
        };
    }
}
